import { ValuesBucket } from '@ohos.data.ValuesBucket'
import relationalStore from '@ohos.data.relationalStore'
import dbHelper from './DbHelper'
import NewsCategory from '../model/NewsCategory'
/****
 * 新闻频道表增删改查
 */
export default class NewsCategoryDao{

    private tableName =  "NewsCategory"
    insert(newsCategory:NewsCategory):Promise<number>{
      var insertData ={
        "id":newsCategory.id,
        "version":newsCategory.version,
        "can_delete":newsCategory.can_delete,
        "category_type":newsCategory.category_type,
        "default_select":newsCategory.default_select,
        "type":newsCategory.type,
        "cart":newsCategory.cart,
        "icon":newsCategory.icon,
        "share_url":newsCategory.share_url,
        "is_share":newsCategory.is_share,
        "share_title":newsCategory.share_title,
        "share_desc":newsCategory.share_desc
      }
     return dbHelper.insert(this.tableName,insertData)
    }
    update(newsCategory:NewsCategory,predicates:relationalStore.RdbPredicates,columns?:Array<string>):Promise<number>{
      var updateData ={
        "id":newsCategory.id,
        "version":newsCategory.version,
        "can_delete":newsCategory.can_delete,
        "category_type":newsCategory.category_type,
        "type":newsCategory.type,
        "cart":newsCategory.cart,
        "icon":newsCategory.icon,
        "share_url":newsCategory.share_url,
        "is_share":newsCategory.is_share,
        "share_title":newsCategory.share_title,
        "share_desc":newsCategory.share_desc
      }
      return dbHelper.update(updateData,predicates,columns)
    }
    query(predicates:relationalStore.RdbPredicates,columns?:Array<string>){
      return dbHelper.query<NewsCategory>(predicates,columns)
    }
    delete(id){
      var predicates =new relationalStore.RdbPredicates(this.tableName).equalTo("id",id)
      return dbHelper.delete(predicates)
    }

}